package org.zpmis.api.http;

import org.springframework.validation.annotation.Validated;
import org.zpmis.api.business.ProjectWebService;
import org.zpmis.common.base.BaseController;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.zpmis.common.exception.BusinessException;
import org.zpmis.common.result.PlatformResult;
import org.zpmis.domain.project.qo.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
* created with CodeGenerator
* description: 项目操作接口
* @author  Yang
* date: 2021-6-2
* time: 14:53:29
*/
@RestController
@RequestMapping("/project")
@Slf4j
public class ProjectController extends BaseController{

    @Resource
    private ProjectWebService projectWebService;


    /**
     * 新增项目信息
     * @param addProjectQo
     * @return
     */
    @PostMapping("addProject")
    public PlatformResult addProject(@Validated @RequestBody AddProjectQo addProjectQo){
        try {
            projectWebService.addProject(addProjectQo);
            return PlatformResult.success();
        } catch (BusinessException e) {
            log.error("[ProjectController]---addProject--->BusinessException:",e);
            return PlatformResult.failure(e.getResultCode());
        } catch (Exception e) {
            log.error("[ProjectController]---addProject--->Exception:",e);
            return PlatformResult.failure();
        }
    }

    /**
     * 修改项目信息
     * @param editProjectQo
     * @return
     */
    @PostMapping("/editProject")
    public PlatformResult editProject(@Validated @RequestBody EditProjectQo editProjectQo){
        try {
            projectWebService.editProject(editProjectQo);
            return PlatformResult.success();
        } catch (BusinessException e) {
            log.error("[ProjectController]---editProject--->BusinessException:",e);
            return PlatformResult.failure(e.getResultCode());
        } catch (Exception e) {
            log.error("[ProjectController]---editProject--->Exception:",e);
            return PlatformResult.failure();
        }
    }

    /**
     * 删除未开始的项目信息
     * @param delProjectQo
     * @return
     */
    @PostMapping("/delProject")
    public PlatformResult delProject(@Validated @RequestBody DelProjectQo delProjectQo){
        try {
            projectWebService.delProject(delProjectQo);
            return PlatformResult.success();
        } catch (BusinessException e) {
            log.error("[ProjectController]---delProject--->BusinessException:",e);
            return PlatformResult.failure(e.getResultCode());
        } catch (Exception e) {
            log.error("[ProjectController]---delProject--->Exception:",e);
            return PlatformResult.failure();
        }
    }

    /**
     * 项目列表查询
     * @param projectListQo
     * @return
     */
    @PostMapping("/projectList")
    public PlatformResult projectList(@RequestBody ProjectListQo projectListQo){
        try {
            return PlatformResult.success( projectWebService.projectList(projectListQo));
        } catch (BusinessException e) {
            log.error("[ProjectController]---projectList--->BusinessException:",e);
            return PlatformResult.failure(e.getResultCode());
        } catch (Exception e) {
            log.error("[ProjectController]---projectList--->Exception:",e);
            return PlatformResult.failure();
        }
    }

    /**
     * 获取所有项目信息集合
     * @param
     * @return
     */
    @PostMapping("/projectAllList")
    public PlatformResult projectAllList(){
        try {
            return PlatformResult.success( projectWebService.projectAllList());
        } catch (BusinessException e) {
            log.error("[ProjectController]---projectAllList--->BusinessException:",e);
            return PlatformResult.failure(e.getResultCode());
        } catch (Exception e) {
            log.error("[ProjectController]---projectAllList--->Exception:",e);
            return PlatformResult.failure();
        }
    }
    /**
     * 获取项目详情
     * @param getProjectDetailQo
     * @return
     */
    @PostMapping("/getProjectDetail")
    public PlatformResult getProjectDetail(@Valid @RequestBody GetProjectDetailQo getProjectDetailQo){
        try {
            return PlatformResult.success(projectWebService.getProjectDetail(getProjectDetailQo));
        } catch (BusinessException e) {
            log.error("[ProjectController]---getProjectDetail--->BusinessException:",e);
            return PlatformResult.failure(e.getResultCode());
        } catch (Exception e) {
            log.error("[ProjectController]---getProjectDetail--->Exception:",e);
            return PlatformResult.failure();
        }
    }


    /**
     * 获取项目任务列表
     * @param getProjectTaskDetailsQo
     * @return
     */
    @PostMapping("/getProjectTaskList")
    public PlatformResult getProjectTaskList(@Valid @RequestBody GetProjectTaskDetailsQo getProjectTaskDetailsQo){
        try {
            return PlatformResult.success(projectWebService.getProjectTaskList(getProjectTaskDetailsQo));
        } catch (BusinessException e) {
            log.error("[ProjectController]---getProjectTaskDetails--->BusinessException:",e);
            return PlatformResult.failure(e.getResultCode());
        } catch (Exception e) {
            log.error("[ProjectController]---getProjectTaskDetails--->Exception:",e);
            return PlatformResult.failure();
        }
    }
}
